import {QUARTZ} from '@/services/api'
import {request, METHOD} from '@/utils/request'

/**
 *
 * @param pageQuery
 * @returns Promise<AxiosResponse>
 */
export async function page(pageQuery) {
    return request(QUARTZ.QUARTZ_PAGE, METHOD.POST, {
        ...pageQuery
    })
}


/**
 *
 * @param id
 * @returns Promise<AxiosResponse>
 */
export async function del(id) {
    return request(QUARTZ.QUARTZ_DELETE + `/${id}`, METHOD.POST, {})
}

/**
 *
 * @param id
 * @returns Promise<AxiosResponse>
 */
export async function execute(id) {
    return request(QUARTZ.QUARTZ_EXECUTE + `/${id}`, METHOD.POST, {})
}

/**
 *
 * @param id
 * @returns Promise<AxiosResponse>
 */
export async function pause(id) {
    return request(QUARTZ.QUARTZ_PAUSE + `/${id}`, METHOD.POST, {})
}

/**
 *
 * @param id
 * @returns Promise<AxiosResponse>
 */
export async function resume(id) {
    return request(QUARTZ.QUARTZ_RESUME + `/${id}`, METHOD.POST, {})
}

/**
 *
 * @param quartz
 * @returns Promise<AxiosResponse>
 */
export async function save(quartz) {
    return request(QUARTZ.QUARTZ_ADD_OR_UPDATE, METHOD.POST, {
        ...quartz,
    })
}

export const columns = [
    {
        title: '任务',
        dataIndex: 'job',
        align: 'center',
    },
    {
        title: '表达式',
        dataIndex: 'cron',
        align: 'center',
    },
    {
        title: '参数',
        dataIndex: 'params',
        align: 'center',
    },
    {
        title: '状态',
        dataIndex: 'status',
        align: 'center',
        scopedSlots: {customRender: 'statusIndex'}
    },
    {
        title: '备注',
        dataIndex: 'remark',
        align: 'center',
    },
    {
        title: '操作',
        align: 'center',
        scopedSlots: {customRender: 'action'}
    }
]
